from django.db import models

class ResourceType(models.Model):
    """
    The type of resource
    """
    name = models.CharField(max_length = 50)
    part = models.FloatField("The part in total cell count (0-100)", null = False)

    def __unicode__(self):
        return self.name
    
    @staticmethod
    def get_random_value():
        types = ()
        for type in ResourceType.objects.all():
            if type.part > 0 : types += ((type.part, type), )
        
        return xunit.select_weighted(types)
